package com.dingtalk.dingbotmgr.action;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Map;

import javax.annotation.Resource;

import com.dingtalk.dingbotmgr.model.User;
import com.dingtalk.dingbotmgr.service.AttachmentService;
import com.dingtalk.dingbotmgr.service.ChatBotMessageService;
import com.dingtalk.dingbotmgr.service.ChatBotService;
import com.dingtalk.dingbotmgr.service.CompanyService;
import com.dingtalk.dingbotmgr.service.PaymentCategoryService;
import com.dingtalk.dingbotmgr.service.PaymentService;
import com.dingtalk.dingbotmgr.service.ProjectService;
import com.dingtalk.dingbotmgr.service.TaskService;
import com.dingtalk.dingbotmgr.service.UserService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.util.ValueStack;
import org.apache.struts2.interceptor.SessionAware;

public abstract class BaseAction extends ActionSupport implements SessionAware {

    @Resource(name = "userService")
    protected UserService userService;

    @Resource(name = "projectService")
    protected ProjectService projectService;

    @Resource(name = "paymentService")
    protected PaymentService paymentService;

    @Resource(name = "paymentCategoryService")
    protected PaymentCategoryService paymentCategoryService;

    @Resource(name = "companyService")
    protected CompanyService companyService;

    @Resource(name = "attachmentService")
    protected AttachmentService attachmentService;

    @Resource(name = "chatBotService")
    protected ChatBotService chatBotService;

    @Resource(name = "chatBotMessageService")
    protected ChatBotMessageService chatBotMessageService;

    @Resource(name = "taskService")
    protected TaskService taskService;

    protected User user;

    protected String msg = "";

    protected String value;

    protected Integer id;

    protected int page;

    protected int rows = 20;

    protected Map<String, Object> session;

    protected ValueStack getValueStack() {
        return ActionContext.getContext().getValueStack();
    }

    public InputStream getInputStream() throws UnsupportedEncodingException {
        return new ByteArrayInputStream(msg.getBytes("utf-8"));
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Override
    public void setSession(Map<String, Object> session) {
        this.session = session;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

}
